<?php
class HknksController extends AppController {

	var $name = 'Hknks';

	function index() {
		$this->Hknk->recursive = 0;
		$this->set('hknks', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid hknk', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('hknk', $this->Hknk->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Hknk->create();
			//debug($this->data);
			if ($this->Hknk->save($this->data)) {
				$this->Session->setFlash(__('Thêm thành công!', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('Không lưu được vào csdl!!!', true));
			}
		}
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid hknk', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Hknk->save($this->data)) {
				$this->Session->setFlash(__('Lưu thành công!', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('Không thể lưu dữ liệu. Kiểm tra lại!', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Hknk->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for hknk', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Hknk->delete($id)) {
			$this->Session->setFlash(__('Hknk deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Hknk was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
